package com.edu.dao.impl;

import com.edu.beans.Admin;
import com.edu.dao.AdminsDao;
import com.edu.utils.JdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class AdminsDaoImpl implements AdminsDao {
    QueryRunner qr = new QueryRunner(JdbcUtils.getDataSource());

    @Override
    public Admin login(String username, String password) {
        try {
            return qr.query("SELECT * FROM tb_admins WHERE username = ? AND password = ?", new BeanHandler<>(Admin.class), username, password);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
